{%- assign seotool = storeConfig.app_seotool_jsonld | strtoarray -%}
{% comment %} https://validator.schema.org/ {% endcomment %}

<!--  LD+JSON WebSite -->
{% if seotool.WebSite.status == 1 or seotool.WebSite.status == nil %}
<script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "WebSite",
    "url": "https://{{ current_domain }}",
    "name": "{{ storeInfo.shop_name }}",
    "potentialAction": [{
        "@type": "SearchAction",
        "target": {
          "@type": "EntryPoint",
          "urlTemplate": "https://{{ current_domain }}/search?q={search_term_string}"
        },
        "query-input": "required name=search_term_string"
      }]
  }
  </script>
{% endif %}

<!--  LD+JSON Organization -->
{% if seotool.Organization.status == 1 or seotool.Organization.status == nil %}
    {% if template == 'comments_list' %}
  <script type="application/ld+json">
  {
     "@context": "http://schema.org",
     "@type": "Organization",
     "name" : "{{ storeInfo.shop_name }}",
     "url": "https://{{ current_domain }}",
      "aggregateRating": {
      "@type": "AggregateRating",
      "ratingValue": "{{ all_comment.statistics.star }}",
      "reviewCount": "{{ all_comment.statistics.count }}"
      },
      "review":[
       {%- for comment in all_comment.comments -%}
        {
        "@type":"Review",
        "author":{
            "@type" : "Person",
            "name":"{{ comment.customer_name | escape  }}"
        },
        "datePublished":"{{ comment.created_at | date: "%Y-%m-%d" }}",
        "reviewBody":"{{ comment.content | escape }}",
        "name":"Review-{{ comment.id }}",
        "reviewRating":{
          "@type" : "Rating",
          "bestRating": "5",
          "ratingValue" : "{{ comment.star }}",
          "worstRating" : "1"
        }
        }{% unless forloop.last %},{% endunless %}
      {%- endfor -%}
        ]
  }

      </script>
      {%- endif -%}
  {%- assign theme_params = storeConfig.theme.params | strtoarray -%}
  <script type="application/ld+json">
  {%- capture link -%}
    {%- if theme_config.global.sns_link_facebook -%}
      ,{{ theme_config.global.sns_link_facebook}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_twitter -%}
      ,{{ theme_config.global.sns_link_twitter}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_pinterest -%}
      ,{{ theme_config.global.sns_link_pinterest}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_instagram -%}
      ,{{ theme_config.global.sns_link_instagram}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_snapchat -%}
      ,{{ theme_config.global.sns_link_snapchat}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_tiktok -%}
      ,{{ theme_config.global.sns_link_tiktok}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_tumblr -%}
      ,{{ theme_config.global.sns_link_tumblr}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_linkedin -%}
      ,{{ theme_config.global.sns_link_linkedin}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_youtube -%}
      ,{{ theme_config.global.sns_link_youtube}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_vimeo -%}
      ,{{ theme_config.global.sns_link_vimeo}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_vk -%}
      ,{{ theme_config.global.sns_link_vk}}
    {%- endif -%}

    {%- if theme_config.global.sns_link_whatsapp -%}
      ,{{ theme_config.global.sns_link_whatsapp}}
    {%- endif -%}

  {%- endcapture -%}
  {% assign links = link | split :","  %}
  {
    "@context": "http://schema.org",
      "@type": "Organization",
       "name" : "{{ storeInfo.shop_name }}",
      "url": "https://{{ current_domain }}",
    "logo": "{{ theme_params.sections.header.settings.pc_logo_pic.src }}",
    "legalName" : "{{ storeConfig.shop_address_company | escape }}",
    "telephone": "{{ storeConfig.shop_address_phone | escape }}",
    "email": "{{ storeConfig.service_email }}",
    "address": {
     "@type": "PostalAddress",
     "streetAddress": "{{ storeConfig.shop_address_line1 | escape }} {{ storeConfig.shop_address_line2 | escape }}",
     "addressLocality": "{{ storeConfig.shop_address_city | escape }}",
     "addressRegion": "{{ storeConfig.shop_address_province_name | escape }}",
     "postalCode": "{{ storeConfig.shop_address_zip | escape }}",
     "addressCountry": "{{ storeConfig.shop_address_country }}"
     },
    "contactPoint": {
     "@type": "ContactPoint",
     "contactType": "Service",
     "telephone": "{{ storeConfig.shop_address_phone | escape }}",
     "email": "{{ storeConfig.service_email }}"
     },
     "sameAs": [
      {%- for item in links -%}
        {%- if item -%}
          "{{- item -}}"{% unless forloop.last %},{% endunless %}
        {%- endif -%}
      {%- endfor -%}
     ]
  }
  </script>
{% endif %}

<!--  LD+JSON BreadcrumbList -->
{% if seotool.BreadcrumbList.status == 1 or seotool.BreadcrumbList.status == nil %}
  {% if template == 'index' %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      }]
    }
  </script>
      {% comment %}3 搜索页{% endcomment %}
  {% elsif template == 'search_detail' and search.keywords == false %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ lang.search.search }}",
        "item": "https://{{ current_domain }}/search"
      }]
    }
  </script>
  {% elsif template == 'search_detail' and search.keywords %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ lang.search.search }}",
        "item": "https://{{ current_domain }}/search"
      },{
        "@type": "ListItem",
        "position": 3,
        "name": "{{ search.keywords | escape }}",
        "item": "https://{{ current_domain }}/search?q={{ search.keywords }}&page=1"
      }]
    }
  </script>
  {% comment %}4 集合列表 {% endcomment %}
  {% elsif template == 'collection_list' %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ lang.general.collections }}",
        "item": "https://{{ current_domain }}/collections"
      }]
    }
  </script>
  {% elsif template == 'collection_detail' %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ lang.general.collections }}",
        "item": "https://{{ current_domain }}/collections"
      },{
        "@type": "ListItem",
        "position": 3,
        "name": "{{ collection.title | escape | default: lang.collections.detail.all_products }}",
        "item": "https://{{ current_domain }}/collections/{{ collection.handle | default: 'all' }}"
      }]
    }
  </script>
  {% elsif template == 'blog_list' %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ lang.blogs.list.news }}",
        "item": "https://{{ current_domain }}/blogs"
      }]
    }
  </script>
  {% elsif template == 'blog_detail' %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ lang.blogs.list.news }}",
        "item": "https://{{ current_domain }}/blogs"
      },{
        "@type": "ListItem",
        "position": 3,
        "name": "{{ blog.title | escape }}",
        "item": "https://{{ current_domain }}/blogs/{{ blog.handle }}"
      }]
    }
  </script>

  {% elsif template == 'page_detail' %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ page.title | escape }}",
        "item": "https://{{ current_domain }}/pages/{{ page.handle }}"
      }]
    }
  </script>
  {% elsif template == 'product_detail' %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      }{%- if product.current_collection -%}
       ,{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ product.current_collection.title | escape }}",
        "item": "https://{{ current_domain }}/collections/{{product.current_collection.handle}}"
      },{
        "@type": "ListItem",
        "position": 3,
        "name": "{{ product.title | escape }}",
        "item": "https://{{ current_domain }}/products/{{ product.handle }}"
      }
    {%- else -%}
    ,{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ product.title | escape }}",
        "item": "https://{{ current_domain }}/products/{{ product.handle }}"
      }
      {%- endif -%}]
    }
  </script>
  {% endif %}
  {% comment %}5 评论列表{% endcomment %}
  {% if template == 'comments_list' %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ lang.comments.title }}",
        "item": "https://{{ current_domain }}/comments"
      }]
    }
  </script>

      {% comment %}6 商品评论页{% endcomment %}
  {% elsif template == 'comments_detail' %}
  <script type="application/ld+json">
      {
      "@context": "http://schema.org",
      "@type": "BreadcrumbList",
      "itemListElement": [{
        "@type": "ListItem",
        "position": 1,
        "name": "{{ lang.layout.navigation.home }}",
        "item": "https://{{ current_domain }}"
      },{
        "@type": "ListItem",
        "position": 2,
        "name": "{{ lang.comments.title }}",
        "item": "https://{{ current_domain }}/comments"
      },{
        "@type": "ListItem",
        "position": 3,
        "name": "{{ product_comment.product.title | escape }}",
        "item": "https://{{ current_domain }}/comments/{{ product_comment.product.handle }}"
      }]
    }
  </script>
  {% endif %}
{% endif %}


<!--  LD+JSON Product -->
{% if seotool.Product.status == 1 or seotool.Product.status == nil %}
  {% if template == 'comments_detail' %}
    {% if product.comment_count > 0 %}
      {% assign star = product.comment_value | divided_by: product.comment_count | round:1 %}
    {% else %}
      {% assign star = 0 %}
    {% endif %}
      {% assign seotool_star = seotool.Product.comment_star | default: 3 %}
      {% assign seotool_people = seotool.Product.comment_people | default: 0 %}
   <script type="application/ld+json">
         {
             "@context": "http://schema.org/",
             "@type": "Product",
             "name": "{{ product_comment.product.title | escape }}",
             "image": [{%- for image_item in product_comment.product.images -%}"{{ image_item.src }}"{% unless forloop.last %},{% endunless %}{%- endfor -%}],
             "description": "{{ product_comment.product.mini_detail | escape }}",
             "mpn": "{{ product_comment.product.spu }}",
         "itemCondition": "http://schema.org/NewCondition",
         "category":"{{ product_comment.product.product_type }}",
             "offers":[{%- for variant_item in variant -%}
             {
                 "@type":"Offer",
                 "priceCurrency": "{{ storeConfig.currency_default }}",
                 "price" : "{{ variant_item.price }}",
                 "itemCondition": "http://schema.org/NewCondition",
                 "mpn": "{{ variant_item.sku }}",
                 "sku": "{{ variant_item.sku }}",
                 "gtin": "{{ variant_item.barcode }}",
                 "url" : "https://{{ current_domain }}/products/{{ product.handle }}?sku_code={{ variant_item.sku_code }}&sku={{ variant_item.sku }}",
                 {% if product.status == 1 %}
         {%- if variant_item.inventory_quantity > 0 -%}
                      "availability" : "http://schema.org/InStock"
                      {%- elsif product.inventory_tracking == 0 -%}
                      "availability" : "http://schema.org/InStock"
                      {%- else -%}
                      "availability" : "http://schema.org/OutOfStock"
                      {%- endif -%}
         {%- else -%}
                      "availability" : "http://schema.org/SoldOut"
                 {%- endif -%}
         }
         {% unless forloop.last %},{% endunless %}
             {%- endfor -%}],
             "url" : "https://{{ current_domain }}/products/{{ product_comment.product.handle }}"
             {%- if product.comment_count >= seotool_people and star >= seotool_star and storeConfig.comments_status == 1 -%}
                 ,
                 "aggregateRating":{
                 "@type":"AggregateRating",
                 "ratingValue":"{{ star }}",
                 "reviewCount":"{{ product_comment.product.comment_count }}"
                 },
                 "review":[
                    {%- for comment_item in product_comment.comments -%}
                         {
                             "@type":"Review",
                             "author":{
                                 "@type" : "Person",
                                 "name":"{{ comment_item.customer_name | escape  }}"
                             },
                             {% if comment_item.created_at > 0 %}
                             "datePublished":"{{ comment_item.created_at | date: "%Y-%m-%d" }}",
                             {% endif %}
                             "reviewBody":"{{ comment_item.content | escape }}",
                             "name":"Review-{{ comment_item.id }}",
                             "reviewRating":{
                                 "@type" : "Rating",
                                 "bestRating": "5",
                                 "ratingValue" : "{{ comment_item.star }}",
                                 "worstRating" : "1"
                             }
                         }
                         {% unless forloop.last %},{% endunless %}
             {%- endfor -%}
                    ]
         {% endif %}

         }

         </script>
  {% elsif template == 'product_detail' %}
  {% if product.comment_count > 0 %}
  {% assign star = product.comment_value | divided_by: product.comment_count | round:1 %}
  {% else %}
  {% assign star = 0 %}
  {% endif %}
  {% assign seotool_star = seotool.Product.comment_star | default: 3 %}
  {% assign seotool_people = seotool.Product.comment_people | default: 0 %}
  <script type="application/ld+json">

        {
            "@context": "http://schema.org/",
            "@type": "Product",
            "name": "{{ product.title | escape }}",
            "image": [{%- for image_item in product.images -%}"{{ image_item.src }}"{% unless forloop.last %},{% endunless %}{%- endfor -%}],
            "description": "{{ product.mini_detail | escape }}",
            "mpn": "{{ product.spu }}",
        "itemCondition": "http://schema.org/NewCondition",
        "category":"{{ product.product_type }}",
            "offers":[
            {%- for variant_item in product.variants -%}
            {
                "@type":"Offer",
                "priceCurrency": "{{ storeConfig.currency_default }}",
                "price" : "{{ variant_item.price }}",
                "name" : "{{ variant_item.option1_value_title }}{%- if variant_item.option2_value_title -%},{{ variant_item.option2_value_title }}{%- endif -%}{%- if variant_item.option3_value_title -%},{{ variant_item.option3_value_title }}{%- endif -%}",
                "itemCondition": "http://schema.org/NewCondition",
                "mpn": "{{ variant_item.sku }}",
                "sku": "{{ variant_item.sku }}",
                "gtin": "{{ variant_item.barcode }}",
                "url" : "https://{{ current_domain }}/products/{{ product.handle }}?sku_code={{ variant_item.sku_code }}&sku={{ variant_item.sku }}",
                {% if product.status == 1 %}
                     {%- if variant_item.inventory_quantity > 0 -%}
                     "availability" : "http://schema.org/InStock"
                     {%- elsif product.inventory_tracking == 0 -%}
                     "availability" : "http://schema.org/InStock"
                     {%- else -%}
                     "availability" : "http://schema.org/OutOfStock"
                     {%- endif -%}
                {%- else -%}
                     "availability" : "http://schema.org/SoldOut"
                {%- endif -%}
            }
            {% unless forloop.last %},{% endunless %}
            {%- endfor -%},
            {
                            "@type": "AggregateOffer",
                            "offerCount": {{ product.variants | size }},
                            "lowPrice": {{ product.variant_price_min }},
                            {% if seotool.Product.price_type > 1 %}
                            "highPrice": {{ product.variant_price_max }},
                            {% endif %}
                            "priceCurrency": "{{ storeConfig.currency_default }}"
                        }
            ],

            "url" : "https://{{ current_domain }}/products/{{ product.handle }}"
            {%- if product.comment_count >= seotool_people and star >= seotool_star and storeConfig.comments_status == 1 -%}
                ,
                "aggregateRating":{
                "@type":"AggregateRating",
                "ratingValue":"{{ star }}",
                "reviewCount":"{{ product.comment_count }}"
                },
                "review":[
                   {%- for comment_item in comments -%}
                        {
                            "@type":"Review",
                            "author":{
                              "@type" : "Person",
                              "name":"{{ comment_item.customer_name | escape }}"
                            },
                            {% if comment_item.created_at > 0 %}
                            "datePublished":"{{ comment_item.created_at | date: "%Y-%m-%d" }}",
                            {% endif %}
                            "reviewBody":"{{ comment_item.content | escape }}",
                            "name":"Review-{{ comment_item.id }}",
                            "reviewRating":{
                                "@type" : "Rating",
                                "bestRating": "5",
                                "ratingValue" : "{{ comment_item.star }}",
                                "worstRating" : "1"
                            }
                        }
                        {% unless forloop.last %},{% endunless %}
                        {%- endfor -%}
                   ]
            {% endif %}
        }
        </script>
  {% endif %}
{% endif %}


<!--  LD+JSON Article -->
{% if template == 'blog_detail' %}
<script type="application/ld+json">
    {
    "@context": "https://schema.org",
    "@type": "Article",
    "url": "https://{{ current_domain }}/blogs/{{ blog.handle }}",
    "mainEntityOfPage": "https://{{ current_domain }}/blogs/{{ blog.handle }}",
    "name": "{{ blog.title | escape }}",
    "author":{
        "@type" : "Person",
        "name":"{{ blog.author_name | escape  }}"
    },
    "publisher": {
      "@type": "Organization",
      "name": "{{ storeInfo.shop_name }}"
      },
    "headline": "{{ blog.title | escape }}",
    "image": {
      "@type": "ImageObject",
      "width": 1024,
      "height": 1024,
      "url": "{{ blog.src }}"
      },
    "datePublished": "{{ blog.published_at | date: "%Y-%m-%d %H:%M:%S" }}",
    "dateCreated": "{{ blog.created_at | date: "%Y-%m-%d %H:%M:%S"}}",
    "dateModified": "{{ blog.updated_at | date: "%Y-%m-%d %H:%M:%S"}}",
    "description": "{{ blog.descript }}" ,
    "articleBody":"{{ blog.content | strip_html | replace:"&nbsp;" , "/r/n" | strip_newlines | escape }}"
    }
  </script>
  {% endif %}
  <!--  LD+JSON End -->